<template>
  <div>
<h2 style="text-align: center;">用户详情页面</h2>


    <table class="table tabel-bordered">

      <tr>
        <td align="right">真实姓名</td>
        <td>
          <input type="text" v-model="state.YH_name">
        </td>
      </tr>
      <tr>
        <td align="right">身份证号码</td>
        <td>
          <input type="text" v-model="state.Y_SFz" maxlength="18">
        </td>
      </tr>
      <tr>
        <td align="right">联系方式</td>
        <td>

          <input type="text" v-model="state.YH_Phone" maxlength="11">
        </td>
      </tr>
      <tr>
        <td align="right">出生年月</td>
        <td>
          <input type="date" v-model="state.Y_date">
        </td>
      </tr>
      <tr>
        <td align="right">总金额</td>
        <td>
          <input type="text" v-model="state.Y_money">
        </td>
      </tr>
      <tr>
        <td align="right">职位</td>
        <td>
          <select v-model="state.YH_id">
            <option value="-1">请选择</option>
            <option :value="item.U_id" v-for="item in list">{{ item.U_name }}</option>

          </select>
        </td>
      </tr>
      <tr>
        <td align="right">性别</td>
        <td>

          <input type="radio" name="sex" v-model="state.U_sex" :value="true">男
          <input type="radio" name="sex" v-model="state.U_sex" :value="false">女
        </td>
      </tr>
      <tr>
        <td align="right">年收入</td>
        <td>
          <input type="text" >



        </td>
      </tr>
      <tr>
        <td align="right">
          <input type="button" value="提交" @click="GEtshu()">
        </td>
        <td></td>
      </tr>

    </table>






  </div>
</template>

<script setup lang="ts">


import { reactive,toRefs,onMounted } from 'vue';

import axios from 'axios';

import { useRoute, useRouter } from 'vue-router';

const route=useRoute();
 const router =useRouter();


 console.log(route.query.id)
//定义数组
  let data:any=reactive({

    list:[]
      ,state:{
        Y_id:route.query.id,
        U_id:route.query.id,
        YH_id:'-1',
        YH_name:'',
        YH_Phone:'',
        Y_date:'',
        U_sex:'',
        Y_money:'',
        Y_SFz:''
      }


  })



let {list}=toRefs(data)

let {state}=toRefs(data)






//就绪函数
onMounted(()=>{


  GEtselect()

})

//下拉框
const GEtselect=()=>{

  axios({
    url:"https://localhost:44385/api/Default/ACCountselect",
    method:"get",
  })
  .then(res=>{

    console.log(res)
      list.value=res.data


  })
  .catch(err=>{

    console.log(err)

  })




}

//提交
  const GEtshu=()=>{

      if(state.value.YH_name=="")
      {
          alert('用户名不能为空')
          return;
      }
      if(state.value.Y_SFz=="")
      {
          alert('身份证号码不能为空')
          return;
      }
      let gh=/^\d{17}[0-9]$/i
      if(gh.test(state.value.Y_SFz)==false)
      {
          alert('身份证不正确')
          return;
      }
      if(state.value.YH_id==-1)
      {
        alert('用户未选择')
        return;
      }
      if(state.value.YH_Phone=="")
      {
        alert('手机号不能为空')
        return;
      }

      let reg=/^1\d{10}$/
        if(reg.test(state.value.YH_Phone)==false)
        {
          alert('手机号输入不正确')
          return;
        }
          if(state.value.Y_date=="")
          {
            alert('出生日期不能为空')
            return;
          }
          if(state.value.Y_money=="")
          {
            alert('年收入不能为空')
            return;
          }
          if(isNaN(state.value.Y_money)==true)
          {
            alert('年收入必须是数字')
            return;
          }
          if(state.value.Y_money<100000)
          {
            alert('年收入不能小于10万')
            return;
          }

          axios({
            url:"https://localhost:44385/api/Default/ShoeGEtAdd",
            method:"post",
            data:state.value,
          })
          .then(res=>{

            if(res.data.data>0)
            {
              alert('添加成功')
            }

          })
          .catch(err=>{

            alert('添加失败')

          })



  }













</script>

<style scoped>

</style>